<template>
  <el-container class="main">
    <el-aside width="230px" class="module leftNav">
      <div>
        <div class="fc">
          <p style="font-size:16px;border-bottom:1px solid rgb(220, 223, 230);padding-bottom:10px;">主题管理
            <span class="fr">
              <el-link icon="el-icon-plus" :underline="false" type="primary" @click="addSubject">添加</el-link>
              <!--<el-link icon="el-icon-delete" :underline="false" type="danger">删除</el-link>-->
            </span>
          </p>
        </div>
        <el-tree ref="subjectTree" :data="subjectTree" node-key="id" default-expand-all :expand-on-click-node="false" :highlight-current="true" @current-change="changeCurSubject">
            <span class="custom-tree-node" slot-scope="{node, subjectTree}">
              <span>{{node.label || node.data.subjectName}}</span>
              <span v-if="node.data.id !='business'&&node.data.id !='sensitive'">
                <i class="el-icon-edit" @click="editSubject(node.data)" style="margin-right:5px;"></i>
                <i class="el-icon-delete" @click="delSubject(node.data.id)"></i>
              </span>
            </span>
        </el-tree>
      </div>
    </el-aside>
    <el-main>
      <div class="module baseInfo" v-if="curSubjectNode">
        <el-row>
          <el-col :span="4">
            <p style="font-size: 18px;padding-bottom: 8px;">主题：{{curSubjectNode.subjectName}}</p>
          </el-col>
          <el-col :span="20">
            <p v-if="curSubjectNode.subjectState=='hasbuild'"><el-button type="success" icon="el-icon-check" circle size="mini" style="margin-top: 5px;"></el-button>已构建</p>
            <p v-else><el-button type="gray" icon="el-icon-setting" circle size="mini" style="margin-top: 5px;"></el-button>未构建</p>
          </el-col>
        </el-row>
        <el-row>
          <p style="font-size: 14px;">{{curSubjectNode.subjectDesc}}</p>
        </el-row>
      </div>
      <el-tabs type="border-card" @tab-click="tabChange" v-model="curTabName">
        <el-tab-pane label="构建管理" name="first">
          <div class="itemTitle">
            语料管理
            <div class="fr itemTitleBtn pr">
              <el-upload style="display: inline-block;" size="mini" :action="'/dictsubjects/'+this.curSubjectID+'/corpuses'"
                         :show-file-list="false"
                         :on-preview="dictCorpusesPreview"
                         :on-success="dictCorpusesSuccess"
                         :on-error="dictCorpusesError">
                <el-button size="small" type="primary">上传</el-button>
              </el-upload>
              <!--<el-button type="primary" plain size="mini">上传</el-button>-->
              <el-button type="danger" plain size="mini">删除</el-button>
            </div>
          </div>
          <el-table border ref="multipleTable" :data="dictCorpusesTable" tooltip-effect="dark" style="width: 100%" @selection-change="handleSelectionChange" v-loading="dictCorpusesLoading">
            <el-table-column type="selection"width="55"></el-table-column>
            <el-table-column prop="corpusName"label="文件名称" show-overflow-tooltip></el-table-column>
            <el-table-column prop="corpusType" label="文件类型" width="150" :formatter="formatterCorpusType"></el-table-column>
            <el-table-column prop="corpusExtension" label="文件拓展名" width="150" ></el-table-column>
            <el-table-column prop="corpusSize"label="文件大小" width="150">
              <template slot-scope="scope">{{ scope.row.corpusSize }}K</template>
            </el-table-column>
            <el-table-column label="操作" width="120">
              <template slot-scope="scope">
                <el-link icon="el-icon-delete" :underline="false" type="danger" @click="delDictCorpuses(scope.row.id)">删除</el-link>
              </template>
            </el-table-column>
          </el-table>
          <div class="fc" style="margin-bottom:15px;margin-top:10px;">
            <el-pagination class="fr" background layout="total, prev, pager, next" :total="dictCorpusesTotalCount" :page-size="dictCorpusesPageSize" @current-change="changeDictCorpusesPage"></el-pagination>
          </div>
          <div class="itemTitle" style="margin-top:0px;margin-bottom:10px;">
            <p class="fl">构建控制</p>
            <div class="fl itemTitleBtn pr" style="padding-left: 30px;">
              <el-button type="primary" @click="setParams()" plain size="mini">参数设置</el-button>
              <el-button type="danger" @click="beginBuild()" plain size="mini">开始构建</el-button>
            </div>
          </div>
          <div class="itemTitle" style="margin-top:20px;margin-bottom:10px;">
            <p class="fl">构建状态</p>
          </div>
          <div class="fc">
            <el-steps :active="buildStateNumber" align-center>
              <el-step title="开始"></el-step>
              <el-step title="语料检查"></el-step>
              <el-step title="参数检查"></el-step>
              <el-step title="执行构建"></el-step>
              <el-step title="完成">
                <template slot="description" v-if="curSubjectNode">
                  <p>{{curSubjectNode.buildDate}}</p>
                </template>
              </el-step>
            </el-steps>
          </div>
        </el-tab-pane>
        <el-tab-pane label="词典维护" name="second">
          <el-container>
            <el-aside width="210px" style="border-right:1px solid #dcdfe6">
              <div class="fc" style="padding:10px;">
                <p style="font-size:14px;border-bottom:1px solid rgb(220, 223, 230);padding-top:2px;padding-bottom:10px;">词典内容：
                  <span class="fr">
                    <el-link icon="el-icon-plus" :underline="false" type="primary" @click="addKeyword">添加</el-link>
                  </span>
                </p>
              </div>
              <el-tree :data="keywordsTree" node-key="id" default-expand-all
                       :expand-on-click-node="false"
                       :highlight-current="true"
                       @current-change="changeCurKeyword"
                       draggable
                       @node-drop="dragEndKeyword">
                  <span class="custom-tree-node el-tree-node__label" slot-scope="{ node, keywordsTree }">
                    <span class="el-tree-node__label">{{ node.data.keywordName}}</span>
                    <span>
                      <i class="el-icon-edit" @click="editKeywordNode(node)" style="margin-right:5px;"></i>
                      <i class="el-icon-delete" @click="delKeyword(node.data.id)"></i>
                    </span>
                  </span>
              </el-tree>
            </el-aside>
            <el-main>
              <div id="treeEchart" style="height:500px;"></div>
            </el-main>
          </el-container>
        </el-tab-pane>
      </el-tabs>
    </el-main>
    <!--主题form表单-->
    <el-dialog :title="subjectFormTitle" :visible.sync="subjectFormVisible" width="400px">
      <el-form :model="subjectForm" :rules="subjectRules" ref="subject" label-width="120px">
        <el-form-item label="主题名称" prop="subjectName">
          <el-input v-model="subjectForm.subjectName" autocomplete="off" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="主题类型" prop="subjectType">
          <el-select v-model="subjectForm.subjectType" placeholder="请选择" size="mini" style="width: 100%">
            <el-option v-for="(item, index) in subjectTypeList" :key="index" :label="item.name" :value="item.val"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="规则说明">
          <el-input type="textarea" v-model="subjectForm.subjectDesc"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="subjectFormVisible = false" size="mini">取 消</el-button>
        <el-button type="primary" @click="submitSubject" size="mini">确 定</el-button>
      </div>
    </el-dialog>
    <!--关键词form表单-->
    <el-dialog :title="keywordsFormTitle" :visible.sync="keywordsFormVisible" width="400px">
      <el-form :model="keywordsForm" label-width="120px">
        <el-form-item label="所属主题" v-if="keywordsForm.parentName">
          <el-input v-model="keywordsForm.parentName" autocomplete="off" size="mini" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="关键词名称">
          <el-input v-model="keywordsForm.keywordName" autocomplete="off" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="关键词拼音">
          <el-input v-model="keywordsForm.keywordPinyin" autocomplete="off" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="关键词英语">
          <el-input v-model="keywordsForm.keywordEnglish" autocomplete="off" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="关键词缩略词">
          <el-input v-model="keywordsForm.keywordAcronym" autocomplete="off" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="关键词类型">
          <el-select v-model="keywordsForm.keywordType" placeholder="请选择" size="mini" style="width: 100%">
            <el-option v-for="(item, index) in keywordTypeList" :key="index" :label="item.name" :value="item.val"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="keywordsFormVisible = false" size="mini">取 消</el-button>
        <el-button type="primary" @click="submitKeyword" size="mini">确 定</el-button>
      </div>
    </el-dialog>
    <!--参数设置form表单-->
    <el-dialog :title="paramsFormTitle" :visible.sync="paramsFormVisible" width="400px">
      <el-form :model="paramsForm" :rules="paramsRules" ref="params" label-width="120px">
        <el-form-item label="主题数量" prop="topicNum">
          <el-input v-model.number="paramsForm.topicNum" autocomplete="off" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="关键词数量" prop="wordNum">
          <el-input v-model.number="paramsForm.wordNum" autocomplete="off" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="超参数(alpha)" prop="alpha">
          <el-input v-model.number="paramsForm.alpha" autocomplete="off" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="超参数(beta)" prop="beta">
          <el-input v-model.number="paramsForm.beta" autocomplete="off" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="迭代次数" prop="itersNum">
          <el-input v-model.number="paramsForm.itersNum" autocomplete="off" size="mini"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="paramsFormVisible = false" size="mini">取 消</el-button>
        <el-button type="primary" @click="submitParams" size="mini">确 定</el-button>
      </div>
    </el-dialog>
  </el-container>
</template>

<script>
export default {
  name: "Dictionary",
  data () {
    return {
      curTabName: 'first',
      subjectTree: [ // -----------------------------------主题管理
        {id: 'business', label: '业务主题', children: []},
        {id: 'sensitive', label: '敏感主题', children: []}
      ],
      subjectTypeList: [
        {name: '业务主题', val: 'business'},
        {name: '敏感主题', val: 'sensitive'}
      ],
      subjectFormTitle: '添加主题',
      subjectFormVisible: false,
      subjectForm: {
        id: '',
        subjectName: '',
        subjectType: '',
        subjectDesc: ''
      },
      subjectRules: {
        subjectName: {required: true, message: '请输入主题名称', trigger: 'blur'},
        subjectType: {required: true, message: '请选择主题类型', trigger: 'blur'}
      },
      curSubjectID: '',
      curSubjectNode: null,
      dictCorpusesTable: [], // ------------------------语料
      dictCorpusesTotalCount: 0,
      dictCorpusesPageSize: 10,
      dictCorpusesLoading: false,
      keywordsTree: [], // -----------------------------关键词
      keywordsFormVisible: false,
      keywordsFormTitle: '添加关键词',
      keywordsForm: {
        id: '',
        keywordName: '',
        keywordPinyin: '',
        keywordEnglish: '',
        keywordAcronym: '',
        keywordType: '',
        parentId: '',
        parentName: ''
      },
      keywordTypeList: [
        {name: '主题', val: 'topic'},
        {name: '关键词', val: 'keyword'}
      ],
      curKeywordNode: null,
      multipleSelection: [],
      treeData: null,
      //----------参数设定-----------
      paramsFormTitle: '参数设置',
      paramsFormVisible: false,
      paramsForm: {
        topicNum: 10,
        wordNum: 10,
        alpha: -1,
        beta: -1,
        itersNum: 1000
      },
      paramsRules: {
        topicNum: [{required: true, message: '请输入主题数量', trigger: 'change'},
                    { type: 'number', message: '只能输入数字', trigger: 'blur' }],
        wordNum: [{required: true, message: '请输入每个主题下关键词数量', trigger: 'change'},
                  { type: 'number', message: '只能输入数字', trigger: 'blur' }],
        alpha: [{required: true, message: '请输入超参数alpha', trigger: 'change'},
                { pattern: /^(0.\d+|-1|1)$/, message: '只能输入(0-1]之间的小数或默认-1', trigger: 'blur' }],
        beta: [{required: true, message: '请输入超参数beta', trigger: 'change'},
                { pattern: /^(0.\d+|-1|1)$/, message: '只能输入(0-1]之间的小数或默认-1', trigger: 'blur' }],
        itersNum: [{required: true, message: '请输入迭代次数', trigger: 'change'},
                  { type: 'number', message: '只能输入数字', trigger: 'blur' }]
      },
      buildStateNumber: 1,
      buildStateTimer: null
    }
  },
  mounted () {
    this.getSubject('subjectType')
  },
  methods: {
    /*
    * 获取主题
    * */
    getSubject (sort) {
      this.axios.get('/dictsubjects?getType=all&sort=' + sort).then(res => {
        if (res.status === 200) {
          // 置空
          this.subjectTree.map(val => {
            val.children = []
          })
          res.data.map((item, index) => {
            let findIndex = this.subjectTree.findIndex(v => v.id === item.subjectType)
            if (findIndex !== -1) {
              this.subjectTree[findIndex].children.push(item)
            }
          })
        } else {
          this.$commonFunc.message({type: 'error', message: res.statusText})
        }
        // 设置默认选择的主题节点
        this.$nextTick(() => {
          if (this.subjectTree[0].children.length > 0) {
            this.curSubjectID = this.subjectTree[0].children[0].id
            this.curSubjectNode = this.subjectTree[0].children[0]
            this.$refs.subjectTree.setCurrentKey(this.curSubjectID)
            this.getDictCorpuses(this.curSubjectID, 1, this.dictCorpusesPageSize, true) // 获取语料
          }
        })
      })
    },
    addSubject () {
      if (this.$refs.subject) {
        this.$refs.subject.resetFields()
      }
      this.subjectFormTitle = '添加主题'
      this.subjectForm.id = ''
      this.subjectForm.subjectName = ''
      this.subjectForm.subjectType = ''
      this.subjectForm.subjectDesc = ''
      this.subjectFormVisible = true
    },
    editSubject (row) {
      if (this.$refs.subject) {
        this.$refs.subject.resetFields()
      }
      this.subjectFormTitle = '编辑主题'
      this.subjectForm.id = row.id
      this.subjectForm.subjectName = row.subjectName
      this.subjectForm.subjectType = row.subjectType
      this.subjectForm.subjectDesc = row.subjectDesc
      this.subjectFormVisible = true
    },
    delSubject (id) {
      let that = this
      this.$commonFunc.message({type: 'confirm', message: '您确定要删除该数据吗?'}, function () {
        that.axios.delete('/dictsubjects/' + id).then(res => {
          if (res.status === 200) {
            that.$commonFunc.message({type: 'success', message: '删除成功'})
            that.getSubject('subjectType')
          } else {
            that.$commonFunc.message({type: 'error', message: res.statusText})
          }
        })
      })
    },
    submitSubject () {
      this.$refs.subject.validate((valid) => {
        if (valid) {
          let url = ''
          let tip = ''
          let method = ''
          if (this.subjectForm.id === '') { // 添加
            url = '/dictsubjects'
            tip = '添加成功'
            method = 'post'
          } else {
            url = '/dictsubjects/' + this.subjectForm.id
            tip = '编辑成功'
            method = 'put'
          }
          this.axios({
            method: method,
            url: url,
            data: {
              subjectName: this.subjectForm.subjectName,
              subjectType: this.subjectForm.subjectType,
              subjectDesc: this.subjectForm.subjectDesc
            }
          }).then(res => {
            if (res.status === 200) {
              this.$commonFunc.message({type: 'success', message: tip})
              this.getSubject('subjectType')
              this.subjectFormVisible = false
            } else {
              this.$commonFunc.message({type: 'error', message: res.statusText})
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    changeCurSubject (val, node) {
      if (val.id !== 'business' && val.id !== 'sensitive') {
        this.curSubjectID = val.id
        this.curSubjectNode = val
        this.tabChange({name: this.curTabName})
      }
    },
    /*
    * 通过subjectID获取语料
    * */
    getDictCorpuses (subjectID, pageNum, pageSize, associated) {
      this.dictCorpusesLoading = true
      this.axios.get('/dictsubjects/' + subjectID + '/corpuses?associated=' + associated + '&pageNum=' + pageNum + '&pageSize=' + pageSize).then(res => {
        if (res.status === 200) {
          this.dictCorpusesTable = res.data.content
          this.dictCorpusesTotalCount = res.data.totalElements
        } else {
          this.$commonFunc.message({type: 'error', message: res.statusText})
        }
        this.dictCorpusesLoading = false
      })
    },
    changeDictCorpusesPage (page) {
      this.getDictCorpuses(this.curSubjectID, page, this.dictCorpusesPageSize, true) // 获取语料
    },
    formatterCorpusType (row, column, cellValue, index) {
      if (row.corpusType === 'file') {
        return '用户文档'
      } else if (row.corpusType === 'wiki'){
        return '百科资源'
      } else {
        return '其他'
      }
    },
    // 文件上传之前
    dictCorpusesPreview (file) {},
    dictCorpusesSuccess (response, file, fileList) {
      this.$commonFunc.message({type: 'success', message: '上传成功'})
      this.getDictCorpuses(this.curSubjectID, 1, this.dictCorpusesPageSize, true) // 获取语料
    },
    dictCorpusesError (err, file, fileList) {
      this.$commonFunc.message({type: 'error', message: err})
    },
    delDictCorpuses (id) {
      let that = this
      this.$commonFunc.message({type: 'confirm', message: '您确定要删除该数据吗?'}, function () {
        that.axios.delete('/dictsubjects/' + that.curSubjectID + '/corpuses/' + id).then(res => {
          if (res.status === 200) {
            that.$commonFunc.message({type: 'success', message: '删除成功'})
            that.getDictCorpuses(that.curSubjectID, 1, that.dictCorpusesPageSize, true) // 获取语料
          } else {
            that.$commonFunc.message({type: 'error', message: res.statusText})
          }
        })
      })
    },
    /*获取关键词*/
    getKeywordsBySubjectID (subjectID) {
      this.axios.get('/dictsubjects/' + subjectID + '/keywords').then(res => {
        if (res.status === 200) {
          this.keywordsTree = res.data
          this.treeEchart()
        } else {
          this.$commonFunc.message({type: 'error', message: res.statusText})
        }
      })
    },
    addKeyword () {
      this.keywordsForm.id = ''
      this.keywordsForm.keywordName = ''
      this.keywordsForm.keywordPinyin = ''
      this.keywordsForm.keywordEnglish = ''
      this.keywordsForm.keywordAcronym = ''
      this.keywordsForm.keywordType = ''
      this.keywordsForm.parentId = ''
      if (this.curKeywordNode) {
        this.keywordsForm.parentName = this.curKeywordNode.keywordName
      } else {
        this.keywordsForm.parentName = ''
      }
      this.keywordsFormTitle = '添加关键词'
      this.keywordsFormVisible = true
    },
    editKeywordNode (node) {
      this.editKeyword(node.data)
      this.keywordsForm.parentName = node.parent.data.keywordName
    },
    editKeyword (row) {
      this.keywordsForm.id = row.id
      this.keywordsForm.keywordName = row.keywordName
      this.keywordsForm.keywordPinyin = row.keywordPinyin
      this.keywordsForm.keywordEnglish = row.keywordEnglish
      this.keywordsForm.keywordAcronym = row.keywordAcronym
      this.keywordsForm.keywordType = row.keywordType
      this.keywordsForm.parentId = row.parentId
      this.keywordsFormTitle = '编辑关键词'
      this.keywordsFormVisible = true
    },
    delKeyword (id) {
      let that = this
      this.$commonFunc.message({type: 'confirm', message: '您确定要删除该数据吗?'}, function () {
        that.axios.delete('/dictsubjects/' + that.curSubjectID + '/keywords/'+ id).then(res => {
          if (res.status === 200) {
            that.$commonFunc.message({type: 'success', message: '删除成功'})
            that.getKeywordsBySubjectID(that.curSubjectID)
          } else {
            that.$commonFunc.message({type: 'error', message: res.statusText})
          }
        })
      })
    },
    submitKeyword () {
      let url = ''
      let tip = ''
      let method = ''
      let parentID = ''
      if (this.keywordsForm.id === '') { // 添加
        url = '/dictsubjects/' + this.curSubjectID + '/keywords'
        tip = '添加成功'
        method = 'post'
        if (this.curKeywordNode) {
          parentID = this.curKeywordNode.id
        }
      } else {
        url = '/dictsubjects/' + this.curSubjectID + '/keywords/' + this.keywordsForm.id
        tip = '编辑成功'
        method = 'put'
        parentID = this.keywordsForm.parentId
      }
      this.axios({
        method: method,
        url: url,
        data: {
          keywordName: this.keywordsForm.keywordName,
          keywordPinyin: this.keywordsForm.keywordPinyin,
          keywordEnglish: this.keywordsForm.keywordEnglish,
          keywordAcronym: this.keywordsForm.keywordAcronym,
          keywordType: this.keywordsForm.keywordType,
          parentId: parentID
        }
      }).then(res => {
        if (res.status === 200) {
          this.$commonFunc.message({type: 'success', message: tip})
          this.getKeywordsBySubjectID(this.curSubjectID)
          this.keywordsFormVisible = false
        } else {
          this.$commonFunc.message({type: 'error', message: res.statusText})
        }
      })
    },
    changeCurKeyword (val, node) {
      this.curKeywordNode = val
    },
    // 拖拽离开节点时
    dragEndKeyword (draggingNode, dropNode, dropType, ev) {
      if (draggingNode.data.parentId === dropNode.data.parentId) { // 同级拖拽不用管
      } else {
        this.editKeyword(draggingNode.data)
        this.keywordsFormVisible = false
        this.keywordsForm.parentId = dropNode.data.parentId
        this.submitKeyword()
      }
    },
    append(node) {
      console.log(node)
      // const newChild = { id: id++, label: 'testtest', children: [] };
      // if (!data.children) {
      //   this.$set(data, 'children', []);
      // }
      // data.children.push(newChild);
    },
    remove(node, data) {
      console.log(node)
      const parent = node.parent;
      const children = parent.data.children || parent.data;
      const index = children.findIndex(d => d.id === data.id);
      children.splice(index, 1);
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    treeEchart () {
      let data = [{name: this.curSubjectNode.subjectName, children: this.keywordsTree}]
      this.$nextTick(() => {
        let myEchart  =this.$echarts.init(document.getElementById('treeEchart'))
        let option = {
          tooltip: {
            trigger: 'item',
            triggerOn: 'mousemove'
          },
          series: [
            {
              type: 'tree',
              data: data,
              top: '1%',
              left: '7%',
              bottom: '1%',
              right: '20%',
              symbolSize: 7,
              label: {
                position: 'left',
                verticalAlign: 'middle',
                align: 'right',
                fontSize: 9
              },
              leaves: {
                label: {
                  position: 'right',
                  verticalAlign: 'middle',
                  align: 'left'
                }
              },
              expandAndCollapse: true,
              animationDuration: 550,
              animationDurationUpdate: 750
            }
          ]
        }
        myEchart.setOption(option)
      })
    },
    tabChange (obj) {
      if (obj.name === 'second') {// 维护
        this.curKeywordNode = null
        this.getKeywordsBySubjectID(this.curSubjectID)
      } else {
        this.getDictCorpuses(this.curSubjectID, 1, this.dictCorpusesPageSize, true) // 获取语料
      }
    },
    //-------参数设定----------
    setParams() {
      this.paramsFormVisible = true
    },
    submitParams() {
      this.$refs.params.validate((valid) => {
        if (valid) {
          this.axios({
            method: 'post',
            url: '/dictsubjects/' + this.curSubjectID + '/model/params',
            data: {
              topicNum: this.paramsForm.topicNum,
              wordNum: this.paramsForm.wordNum,
              alpha: this.paramsForm.alpha,
              beta: this.paramsForm.beta,
              itersNum: this.paramsForm.itersNum,
            }
          }).then(res => {
            if (res.status === 200) {
              this.$commonFunc.message({type: 'success', message: '设置成功'})
              this.paramsFormVisible = false
            } else {
              this.$commonFunc.message({type: 'error', message: res.statusText})
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    beginBuild() {
      let tip = ''
      let that = this
      if(this.curSubjectNode.buildDate) {
        tip = '重新构建原词典将被删除，您确定要执行吗？'
      }else{
        tip = '您确定要执行构建吗？'
      }
      this.$commonFunc.message({type: 'confirm', message: tip}, function () {
        that.axios({
          method: 'post',
          url: '/dictsubjects/' + that.curSubjectID + '/model',
        }).then(res => {
          if (res.status === 200) {
            that.$commonFunc.message({type: 'success', message: '构建中...'})
            that.getState()
          } else {
            that.$commonFunc.message({type: 'error', message: res.statusText})
          }
        })
      })
    },
    getState() {
      clearTimeout(this.buildStateTimer)
      this.axios.get('/dictsubjects/' + this.curSubjectID + '/model/state').then(res => {
        if (res.status === 200) {
          if (res.data === 'checking-corpus') {
            this.buildStateNumber = 2
          } else if (res.data === 'checking-params') {
            this.buildStateNumber = 3
          } else if (res.data === 'building') {
            this.buildStateNumber = 4
          } else if (res.data === 'builded') {
            this.buildStateNumber = 5
            this.$commonFunc.message({type: 'success', message: '构建完成'})
            this.axios.get('/dictsubjects/' + this.curSubjectID).then(res => {
              if (res.status === 200) {
                this.curSubjectNode.buildDate = res.data.buildDate
              }
            })
          } else if (res.data === 'error') {
            this.$commonFunc.message({type: 'error', message: '构建出错，请确认已经上传语料，并设定了构建参数'})
          }
          if (res.data != 'builded' && res.data != 'error') {
            let that = this
            this.buildStateTimer = setTimeout(() => {
              that.getState()
            }, 2000)
          }
        }
      })
    }
  }
}
</script>
<style>
  .baseInfo .el-button--mini.is-circle{
    padding:0px;
    margin-right:5px;
  }
</style>
<style scoped>

</style>
